#ifndef PRIMITIVELINE_H_INCLUDED
#define PRIMITIVELINE_H_INCLUDED

#include "../RenderableLine.h"
#include "../cvIPrimitives.h"
#include "../CollectionNode.h"
#include "../CollectionTypes.h"

namespace cvImmediateModeRenderer
{
	// TODO: sizeof(cvVert)*2+sizeof(RGBAf)*2 == sizeof(line_struct) must be true.
	struct line_struct
	{
		line_struct() : v2(10.0f, 10.0f)	{}	// set second vertex for debugging.
		cvVert v1;
		RGBAf c1;
		cvVert v2;
		RGBAf c2;
	};

	class Line : public cvRenderInterface::RenderableLine
	{
		public:
			/// #2 Node allocator
			static Line * create();
			static Line * createSingleshot();
			virtual void destroy();
			static void purgeMemoryPool();

			virtual cvRenderInterface::CollectionNode * createCollection();
			virtual cvRenderInterface::CollectionNode * requestCollection();

			/// #4 Collections

			/// @returns type is line_struct
			virtual void * getStorgatePtr() const;

			/// @param targetptr and @param sourceptr are type of line_struct
			virtual void remapStorgate(cvRenderInterface::CollectionNode * node, void * sourceptr, void * targetptr);

			/// #7 rendering phases:
			virtual void processCollect(const cvObjects::BaseCameraObject * camera);
			virtual void processTransfer();
			virtual void processRender();

			/// attribute writers
			virtual void verts(const cvVert &v1, const cvVert &v2);
			virtual void color(const RGBAf &col);
			virtual void colorv1(const RGBAf &col);
			virtual void colorv2(const RGBAf &col);

		protected:
			Line();
			~Line();

		private:
			/** Memory allocation */
			void * operator new(size_t);
			void operator delete(void*);
			void * operator new[] (size_t);	// never implement
			void operator delete[] (void*);	// never implement
			static cvPool  m_pool;			//pool for Line objects itself
			static cvPool  m_structpool;	//pool for lone line_structs

			/// ptr to Renderable
			line_struct * m_target;
	};
};

#endif // PRIMITIVELINE_H_INCLUDED
